<template>
  <div class="carouse_manage">
    <header>
      <el-button size="mini" type="primary" @click="addGoodsShow = true">添加商品</el-button>
    </header>

    <section>
      <el-table :data="tableData" height="100%" border>
        <el-table-column label="轮播图片" prop="" align="center">
          <template slot-scope="scope">
            <img style="width: 200px;height: 100px;" :src="scope.row.fileUrl">
          </template>
        </el-table-column>
        <el-table-column label="所属商家" prop="shopName" align="center"></el-table-column>
        <el-table-column label="商品名称" prop="goodsName" align="center"></el-table-column>
        <el-table-column label="商品类型" align="center">
          <template slot-scope="scope">
            {{scope.row.itemType | typeFilter}}
          </template>
        </el-table-column>
        <el-table-column label="商品信息" prop="" align="center"></el-table-column>
        <el-table-column label="排序" prop="" align="center"></el-table-column>
        <el-table-column label="线上展示状态" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isShow"
              @change="changeStatus(scope.row)">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作" prop="" align="center"></el-table-column>
      </el-table>
    </section>

    <footer>
      <el-pagination
        :current-page="searchForm.currentPage"
        :page-sizes="[10, 15, 20, 30]"
        :page-size="searchForm.pageSize"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        align="center"
        style="margin-top: 10px;"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </footer>

    <el-dialog title="添加商品" :visible.sync="addGoodsShow" width="520px" :close-on-click-modal="false" :close-on-press-escape="false" :append-to-body="true">
      <addGoods v-if="addGoodsShow" @closeDialog="addGoodsShow = false" @refresh="getTableData" />
    </el-dialog>

  </div>
</template>

<script>
  import addGoods from './addGoods.vue'

  export default {
    components: { addGoods },
    filters: {
      typeFilter(type) {
        return type == 1 ? '商品' : '优惠券'
      }
    },
    data() {
      return {
        searchForm: {
          currentPage: 1,
          pageSize: 10
        },
        total: 10,
        tableData: [],
        addGoodsShow: false
      }
    },
    mounted() {
      this.getTableData();
    },
    methods: {
      getTableData() {
        this.$axios({
          method: 'get',
          url: '/shop/shop-slide-show/getShopSlideShowPage',
          params: this.$qs.stringify(this.searchForm)
        }).then((res) => {
          console.log(444555,res)
          if(res.code == 200) {
            res.data.records.forEach(item => {
              item.isShow = item.isShow == 1 ? true : false
            })
            this.tableData = res.data.records;
          }
        })
      },

      changeStatus(item) {
        let data = {};
        data.showId = item.id;
        data.isShow = item.isShow == true ? 1 : 2;
        this.$axios({
          method: 'post',
          url: '/shop/shop-slide-show/isShow',
          data: this.$qs.stringify(data)
        }).then((res) => {
          if(res.code == 200) {
            this.$message.success('修改展示状态成功')
          }
        })
      },

      // 分页修改每页显示条数
      handleSizeChange(val) {
        this.searchForm.pageSize = val;
        // this.getTableData();
      },
      // 分页跳转页面
      handleCurrentChange(val) {
        this.searchForm.currentPage = val;
        // this.getTableData();
      },
    }
  }
</script>

<style scoped>
  .carouse_manage {
    height: calc(100vh - 158px);
  }

  header {
    height: 50px;
  }

  section {
    height: calc(100% - 90px);
  }

  footer {
    height: 40px;
  }




</style>
